// Ajax 文件下载
jQuery.downloadInterface = function(url, method, data) {

    data = data||{};

    if( url && data ) { 

        var inputs = '';
        if (method == 'get') {
            data = typeof data == 'string' ? data : jQuery.param(data);
            jQuery.each(data.split('&'), function(){ 
                var pair = this.split('=');
                inputs+='<input type="hidden" name="'+ pair[0] +'" value="'+ pair[1] +'" />'; 
            });        // request发送请求
        } else {
            inputs+='<input type="hidden" name="postData" value="'+ JSON.stringify(data).replace(/"/g, "'") +'" />';
        }
        
        jQuery('<form action="'+ url +'" method="'+ (method||'post') +'">'+inputs+'</form>')
        .appendTo('body').submit().remove();
    };
};

// Ajax 文件上传
jQuery.importInterface = function(url, method) {

    if(url) { 

        jQuery("#importInterface").remove();

        var inputs = '<input type="file" name="file" class="importClick" hidden/>';

        jQuery('<form id="importInterface" action="'+ url +'" method="'+ (method||'post') +'" enctype="multipart/form-data">'+inputs+'</form>')
        .appendTo('body');
        jQuery(".importClick").trigger("click");
        jQuery(".importClick").on("change", function() {
            $("form#importInterface").ajaxSubmit({
                // type: "get",
                // url: $.getRadParamUrl(jsons("CSM_IMPORT")),
                success: function (data) {

                    if (data.data == 1) {
                        _as.jAlert("批量导入成功", function() {
                            location.reload();
                        });
                    } else {
                        _as.jAlert("批量导入失败");
                    }
                },
                error: function (msg) {
                    _as.jAlert("批量导入失败");
                }
            });
        })
    };
};